package com.situ.mall;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ShenNanDaDao {
    public static void main(String[] args) {
        String[] array = {"2019 5013 08", "2019-5013-08", "2019501308"};
        String regex = "(\\d{4})[\\-\\s]?(\\d{4})[\\-\\s]?(\\d{2})";
        Pattern pattern = Pattern.compile(regex);
        for (String string : array) {
            Matcher matcher = pattern.matcher(string);
            if (matcher.find()) {
                //group(0)代表匹配的整个字符串
                //System.out.println(matcher.group(0));
                System.out.println(matcher.group(1) + "-" + matcher.group(2) + "-" + matcher.group(3));
            }
        }
    }
}
